<?php
include("header.php");
include("connect.php");

$query = "select Publication.ID as 'PublicationID', 
		Publication.Name as 'PublicationName', 
		Publication.DatePublished as 'DatePublished', 
		Notification.Name as 'NoticeType', 
		Country.Name as 'Country'  
		from PublicationPerson left join Publication on Publication.ID = PublicationPerson.PublicationID 
		left join Notification on Publication.NotificationID = Notification.ID left join Country on Publication.CountryID = Country.ID where PersonID = ".mysql_real_escape_string($_GET['ID']);


//echo $query;

// Perform Query
$result = mysql_query($query, $link);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

$class1 = "odd";
$class2 = "even";
$class = $class1;

echo "<table><tr><th>Publication ID</th><th>Name</th><th>Date Published</th><th>Notice Type</th><th>Country</th></tr>\n";
while ($row = mysql_fetch_assoc($result)) {
	echo "<tr class=\"$class\">\n";
	echo "<td><a href=\"publicationperson.php?publication=".str_replace("&", "&amp;", $row['PublicationID'])."\">".str_replace("&", "&amp;", $row['PublicationID'])."</a></td>";
echo "<td>".str_replace("&", "&amp;", $row['PublicationName'])."</td>";
echo "<td>".str_replace("&", "&amp;", $row['DatePublished'])."</td>";
echo "<td>".str_replace("&", "&amp;", $row['NoticeTyoe'])."</td>";
echo "<td>".str_replace("&", "&amp;", $row['Country'])."</td></tr>\n";
if($class == $class1) {
	$class = $class2;
} else if ($class == $class2) {
	$class = $class1;
}

}
echo "</table></body></html>";


// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);
mysql_close($link);
?>
